package de.mmis.helferlein.demo;

import java.util.Timer;
import java.util.TimerTask;

import de.mmis.core.base.DeserializableAnnotations.ConstructorDeserializable;
import de.mmis.core.base.DeserializableAnnotations.DeserializationConstructor;
import de.mmis.core.base.MethodDescriptor.P;
import de.mmis.core.base.event.AbstractObservable;
import de.mmis.core.base.event.Event;

public class FloatProducer extends AbstractObservable<FloatProducer.FloatEvent> {

	@ConstructorDeserializable(typeIdentifier = "float-event")
	public static class FloatEvent implements Event {
		private final float number;

		@DeserializationConstructor
		public FloatEvent(@P("Number") float n) {
			number = n;
		}

		public float getFloat() {
			return number;
		}
	}

	private float n = (float) Math.PI;

	public FloatProducer(long period) {
		Timer timer = new Timer(true);
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				fireEvent(new FloatEvent(n));
				n *= 2;
			}
		}, 1000, period);
	}

	public float getFloat() {
		return n;
	}
}
